package com.Z形翻转;

public class Solution {

	 public String convert(String s, int numRows) {
	        char[] c = new char[s.length()];
	        int i,index;
	        int ci=0;
	        if(numRows==1){
	            return s;
	        } 
	        for(i=1;i<=numRows;i++){
	            index=i-1;
	            if(i==1||i==numRows){
	                while(index<s.length()&&ci<s.length()){
	                	
	                    c[ci]=s.charAt(index);
	                    ci++;
	                    index=index+2*(numRows-1);
	                }
	            }
	            else{
	                while(index<s.length()&&ci<s.length()){
	                	
	                    c[ci]=s.charAt(index);
	                    ci++;
	                    if(index+2*(numRows-i)<s.length()){
	                    
	                        c[ci]=s.charAt(index+2*(numRows-i));
	                        ci++;
	                        index = index+2*(numRows-1);
	                    }
	                    else {
	                    	break;//如果下一个2*(numRows-i)回的数不存在，就结束当前层的统计
	                    }
	                }
	            }
	        }
	        String S = new String(c);
	        return S;
	    }

}
